import { useEffect, useRef } from 'react';
import { Drawer, Spin } from 'antd';
import pageStyles from '@/common/pageLayout.less';
import ScrollBarLayout from '@/components/ScrollBarLayout';
import { DetailDrawerInfoView } from './DetailDrawerInfoView';
import { getKeyRouter } from '@/utils';
import Cls from 'classnames';
import '../common/style.less';
import { getDelegateByIdService } from '../services';

const deleGateCheckDomID = `deleGate-${getKeyRouter()}`;

export const DetailDrawer: React.FC<DelegateManageAPI.IDetailDrawer> = ({ onClose, isShowDetail, recordObj, curRes }) => {
  const prefixCls = 'delegate-detail-';

  /** 申请页ref */
  const tipErrorModalRef: any = useRef();

  /** 详情接口回调 */
  const detailCallback = (res: any) => {
    // if (res && res?.msgFlag) {
    //   message.success(res?.msg);
    // } else {
    //   message.error(res?.msg);
    // }
  };

  /** 获取详情接口 */
  const { getDelegateByIdInfo, getDelegateByIdLoading, getDelegateByIdRun } = getDelegateByIdService(detailCallback);

  useEffect(() => {
    if (recordObj && recordObj?.id) {
      getDelegateByIdRun({
        id: recordObj?.id,
      });
    }
  }, [recordObj]);

  return (
    <>
      <Drawer
        className={pageStyles['detailDrawerDes']}
        title="委托详情"
        style={{ position: 'absolute', height: '100%', overflow: 'hidden' }}
        placement="right"
        onClose={onClose}
        open={isShowDetail}
        getContainer={false}
        width={document.body?.clientWidth * 0.45}
        bodyStyle={{ padding: 0 }}
        closable={false}
        destroyOnClose={true}
        // extra={extraRender()}
      >
        <Spin spinning={getDelegateByIdLoading}>
          <div
            className={Cls('commonDrawerBodyDom')}
            id={deleGateCheckDomID}
            style={{
              // height: checkDrawerBool ? `calc(100% - 225px)` : `100%`,
              height: `100%`,
            }}
          >
            <div className="drawerBodyInfoDom">
              <ScrollBarLayout style={{ padding: '5px 10px' }}>
                <DetailDrawerInfoView curRes={curRes} detailInfo={getDelegateByIdInfo} />
              </ScrollBarLayout>
            </div>
          </div>
        </Spin>
      </Drawer>
    </>
  );
};
